<?php 
    $lang = "en";
    $temp = null;
    $jobID = null;
    $edit = "index.php?r=JobsManage/Edit";
    $add = "index.php?r=JobsManage/Add";
    $mode = empty($_REQUEST['mode'])?"Add":$_REQUEST['mode'];
    if($mode == "Edit") {
        $head = "Edit position";
        $jobID = $_REQUEST['jobID'];
        $actions = $edit;
        $temp = JobsManage::GetInfoByID($jobID, $lang);
    }else {
        $head = "Insert position";
        $actions = $add;
    }
    
    $positionEN = isset($temp['PositionEN'])?$temp['PositionEN']:null;
    $positionTH = isset($temp['PositionTH'])?$temp['PositionTH']:null;
    $sex        = isset($temp['Sex'])?$temp['Sex']:null;
    $age        = isset($temp['Age'])?$temp['Age']:null;
    $exp        = isset($temp['Exp'])?$temp['Exp']:null;
    $salary     = isset($temp['Salary'])?$temp['Salary']:null;
    $provinceID = isset($temp['ProvinceID'])?$temp['ProvinceID']:null;
    $locationEN = isset($temp['LocationEN'])?$temp['LocationEN']:null;
    $locationTH = isset($temp['LocationTH'])?$temp['LocationTH']:null;
    $descriptEN = isset($temp['DescriptEN'])?$temp['DescriptEN']:null;
    $descriptTH = isset($temp['DescriptTH'])?$temp['DescriptTH']:null;
    $state      = isset($temp['State']) ? $temp['State'] == 'O' ? $temp['Urgent'] == 'U' ? "U" : "O" : "C" : null;
    $urgent     = isset($temp['Urgent'])?$temp['Urgent']:null;
    $createdate = isset($temp['CreateDate'])?$temp['CreateDate']:date("Y-m-d");
?>
<script>
    
</script>
<div>
    <p><h2 class="head">Position Details</h2></p>
    <hr/>  
</div>
<!--TAB-->
<form action="<?=$actions;?>" method="post" mode="<?=$mode?>" data_gender="<?=$sex?>" data_province="<?=$provinceID?>" data_state="<?=$state?>">
<div>
    <ul class="nav nav-tabs" id="tabZone">
        <li class="active"><a href="#EN" data-toggle="tab" title="Position detail in english">EN</a></li>
        <li><a href="#TH" data-toggle="tab" title="Position detail in thai">TH</a></li>
    </ul>
    <div class="tab-content">
        <div class ="tab-pane  active" id="EN">
            <div class="hero-unit"><h4><?=$head . " : English detail\n";?></h4>
                <div class="controls controls-row">
                    <div class="form-horizontal">
                        <input type="hidden" id="jobID" name="jobID" value="<?=$jobID;?>"/>
                        <div class="control-group">
                            <label for="positionEN" class="control-label required">Position</label>
                            <div class="controls">
                                <input name="positionEN" class="span5" type="text" placeholder="" value="<?=$positionEN; ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="gender" class="control-label">Gender</label>
                            <div class="controls">
                                <select name="gender" id="gender" style="width: 9em">
                                    <option value = '' selected>Not specified</option>
                                    <option value = 'M'>Male</option>
                                    <option value = 'F'>Female</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="age" class="control-label">Age</label>
                            <div class="controls">
                                <input name="age" class="span4" type="text" placeholder="" value="<?=$age; ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="salary" class="control-label">Salary</label>
                            <div class="controls">
                                <input name="salary" class="span4" type="text" placeholder="" value="<?=$salary; ?>">
                            </div>
                        </div>
                         <div class="control-group">
                            <label for="exp" class="control-label">Experience</label>
                            <div class="controls">
                                <input name="exp" class="span4" type="text" placeholder="" value="<?=$exp;?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="provinceID" class="control-label required">Province</label>
                            <div class="controls">
                                <select name="provinceID" id="provinceID">
                                    <?= GM::getOptionDropdownProvince($lang); ?>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="locationEN" class="control-label required">Location</label>
                            <div class="controls">
                                <input name="locationEN" class="span4" type="text" placeholder="" value="<?=$locationEN; ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="jobdesEN" class="control-label required">Job Description</label>
                            <div class="controls">
                                <textarea id="jobdesEN" name="jobdesEN" rows="10" class="span8"><?=$descriptEN; ?></textarea>
                            </div>
                        </div>
                        <input type="hidden" id="urgent" name="urgent" value="<?=$urgent;?>"/>
                        <div class="control-group">
                            <label for="state" class="control-label">State</label>
                            <div class="controls">
                                <select name="state" id="state" style="width: 7em">
                                    <option value="O" selected >OPEN</option>
                                    <option value="U">URGENT</option>
                                </select>
                            </div>
                        </div>
                        <div><input id="createdate" name="createdate" type="hidden" value="<?=$createdate ?>"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class ="tab-pane" id="TH">
            <div class="controls controls-row">
                <div class="hero-unit"><h4><?=$head . " : ข้อมูลภาษาไทย\n";?></h4>
                <div class="form-horizontal">
                    <div class="control-group">
                        <label for="positionTH" class="control-label required">ตำแหน่ง</label>
                        <div class="controls">
                            <input name="positionTH" class="span5" type="text" placeholder="" value="<?=$positionTH; ?>">
                        </div>
                    </div> 
                    <div class="control-group">
                        <label for="locationTH" class="control-label required">สถานที่ตั้ง</label>
                        <div class="controls">
                            <input name="locationTH" class="span4" type="text" placeholder="" value="<?=$locationTH; ?>">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="jobdesTH" class="control-label required">รายละเอียด</label>
                        <div class="controls">
                            <textarea id="jobdesTH" name="jobdesTH" rows="10" class="span8"><?=$descriptTH; ?></textarea>
                        </div>
                    </div>
                </div>  
                </div>
            </div>
        </div>
    </div>
    <div><input type="submit" class="btn btn-large" data-loading-text="Loading..." value ="Save"></div>
</div>
</form>
<script>
    $(document).ready(function(){
        var mode = $('form').attr('mode');
        var sex = $('form').attr('data_gender');
        var provinceID = $('form').attr('data_province');
        var state = $('form').attr('data_state');
		
        sex = "option[value=\"" + sex + "\"]";
        provinceID = "option[value=\"" + provinceID + "\"]";
        state = "option[value=\"" + state + "\"]";
        $('select#gender').find(sex).attr('selected',true);
        $('select#provinceID').find(provinceID).attr('selected',true);
        if(mode == "Edit"){ $('select#state').append("<option value=C>CLOSE</option>"); }
        $('select#state').find(state).attr('selected',true);

        $('textarea').ckeditor({customConfig: "JobManage_CK.js"});
    });
</script>
<style>
    .btn {
        float:right;
    }
    .head {
        font-weight:bold;
        color: #003080;
    }
    hr {
        color: #f00;
        background-color: #f00;
        height: 5px;
    }
</style>